@extends('template.adminpage')
@section('content')
<ol class="breadcrumb">
  <li class="active">Laporan agen</li>
</ol>
			

<div class="container-black">
			<div class="row" style="margin-top:5px">
                <div class="col-md-7">
                <label><u>Laporan bulanan</u></label>
                </div>
                <div class="col-md-5">
                <form action="agenperbulan" method="POST">
                <div class="input-group" >
                  <select class="form-control" name="bulan" style="height:30px">
                    <?php 
                        $bulan = array('Januari' => 1, 'Februari' => 2, 'Maret' => 3, 'April' => 4, 'Mei' => 5, 'Juni' => 6, 'Juli' => 7, 'Agustus' => 8, 'September' => 9 , 'Oktober' => 10, 'November' => 11, 'Desember' => 12  );;
                        foreach($bulan as $key => $val){
                          if($val == $b){
                            echo '<option value="'.$val.'" selected>'.$key.'</option>';
                          }else{
                            echo '<option value="'.$val.'">'.$key.'</option>';
                          }
                        }
                      ?>
                  </select>
                  <span class="input-group-btn">

                  <select class="form-control" name="tahun" style="width:100px;height:30px">
                    <option value="">Tahun</option>
                    <?php for ($i = 2011; $i < 2033; $i++){
                      if($i == $t){
                            echo '<option value="'.$i.'" selected>'.$i.'</option>';
                          }else{
                            echo '<option value="'.$i.'">'.$i.'</option>';
                          }
                    } 
                    ?>
                  </select>
                  </span>
                  <span class="input-group-btn">
                    <button class="btn btn-dark" type="submit" style="height:30px"><span class="glyphicon glyphicon-search"></span> Lihat</button>
                  </span>
                </div><!-- /input-group -->
                 </form>
                </div>
            </div>	
            <legend style="margin-bottom:0px; margin-top:5px"></legend>
  <h3 align="center">Laporan agen bulan <?php foreach($bulan as $key=>$val){ if($val == $b){ echo $key.' '.$t;} }?> </h3>
                       <label><u>Summary</u></label>

  						      <div class="row" style="margin-top:10px">
                              <div class="col-md-8 col-md-offset-2">

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Total agen bergabung</label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{$jumlahagen}} Agen</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Total agen aktif</label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{$jumlahagenaktif}} Agen</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Total agen tidak aktif</label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{$jumlahagentidakaktif}} Agen</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Total agen per kabupaten / kota</label>
                                  </div>
                                  <div class="col-lg-7">
                                  		<table class="table">
											<tr><th>Kabupaten / Kota </th><th>Jumlah Agen</th></tr>
											<?php
						                	foreach($regionalall as $tp){
											$agenystrd = DB::table('sys_member')
  													->whereBetween('member_joindate', array($t.'-'.$b.'-01 00:00:00', $t.'-'.$b.'-31 23:59:59'))
													->where('member_regional_id',$tp->member_regional_id)
													->count();
											$reg = DB::table('ref_regional')
													->where('regional_id',$tp->member_regional_id)
													->first();
											?>
											<tr><td>{{$reg->regional_name}} </td><td>{{$agenystrd}} Agen</td></tr>
										<?php	} ?>
					               		 </table> 
                                  </div>
                                  </div>


                              </div> 
                              </div>   
                       <label><u>Daftar agen</u></label>
    <br>
    <form action="agensearch" method="POST">


  		  <div class="row">
      <div class="col-md-9">
        <div class="col-md-1">
          <input name="filter" value="type" type="radio" checked ></input>
        </div>
        <div class="col-lg-3">
        <label>Status</label>
        </div>
        <div class="col-lg-3">
           <select  class="form-control" name="typeby" style="height:30px" />
            <?php
            $type = array('all'=>'All','Aktif' => 'Aktif','Tidak aktif' => 'Tidak aktif');
            foreach ($type as $key => $val) {
                if ($key == Session::get('typeby')) {
                    echo '<option value="' . $key . '" selected>' . $val . '</option>';
                } else {
                    echo '<option value="' . $key . '">' . $val . '</option>';
                }
            }
            ?>
          </select>
        </div>
      </div>
      </div>
      <br>


      <div class="row">
      <div class="col-md-9">
        <div class="col-md-1">
          <input name="filter" value="keyword" type="radio"></input>
        </div>
        <div class="col-lg-3">
        <label>Kata kunci</label>
        </div>
        <div class="col-lg-3">
          <input type="text"  class="form-control" placeholder="Kata kunci" name="keyword" style="height:30px" /></input>
        </div>
        <div class="col-lg-3 col-md-offset-1">
          <select name="filterby" class="form-control" style="height:30px" />
            <option value="agencode">Kode agen</option>
            <option value="referalcode">Kode referal (sponsor)</option>
            <option value="agenname">Nama agen</option>
          </select>
        </div>
      </div>
      </div>
      <br>
      <div class="row">
      <div class="col-md-9">
        <div class="col-md-3 col-md-offset-4">
             <button class="btn btn-sm btn-dark" type="submit" style="height:30px"><span class="fa fa-search"></span> Tampilkan</button>
        </div>
      </div>
      </div>
        

    </form>
    <a href="{{URL::to('/report/agenexportxls')}}" target="_blank"><button class="btn btn-xs btn-info pull-right" style="margin-bottom:5px"><span class="fa fa-print"></span> Export excel</button></a><br>
<?php  
        $limit = 10;
        if(Input::get('page')==0 OR Input::get('page')==1){ 
         $no = 1;
        }
        else{
        $no = ((Input::get('page')-1)*$limit)+1;
        }
       ?>
  	 <table class="table table-bordered table-hover">
      <thead>
        <tr>
          <th>No</th>
          <th>Kode agen</th>
          <th>Nama agen</th>
          <th>Referal</th>
          <th>No telp / HP</th>
          <th>Tgl join</th>
          <th>Status</th>
          <th>Aksi</th>
        </tr>
      </thead>
      <tbody>
        <tr>
       
       @foreach($dataagen as $agen)
       <?php $refc = DB::table('sys_agen')
                  ->where('agen_id',$agen->agen_sponsor_id) 
                  ->count();
              $ref = DB::table('sys_agen')
                  ->where('agen_id',$agen->agen_sponsor_id) 
                  ->first();
              if($refc==0){
                $code = 'Perusahaan';
              }else{
                $code = $ref->agen_code;
              }

              $agenacc = DB::table('sys_account_agen')
                      ->where('account_agen_id',$agen->agen_id)
                      ->count();
                  ?>
         <td>{{$no}}</td>
         <td>{{$agen->agen_code}}</td>
         <td>{{$agen->member_name}}</td>
         <td>{{$code}}</td>
         <td>{{$agen->member_phone}}</td>
         <td>{{date("d-M-Y",strtotime($agen->member_joindate))}}</td>
         <td>{{$agen->member_status}}</td>

          <td style="width:150px"><a data-toggle="modal" data-target="#detail{{$agen->agen_id}}" title="Agen Detail"><button class="btn btn-xs btn-dark" ><span class="fa fa-file"></span> Detail</button></a></td>
        <?php $no++; ?>
      </tr>
      @endforeach
      </tbody>


    </table>
  <div class="text-right"><?php echo $dataagen->links(); ?></div>
  </div>
  </form>

 @foreach($dataagen as $agen)
 <div class="modal fade" id="detail{{$agen->agen_id}}" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
                <div class="modal-dialog modal-lg">
                  <div class="modal-content">
                    <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
 
                    <h4 align="center" class="modal-title"> <label style="margin-top:5px; margin-bottom:5px">Agen detail</label></h4>
                    </div>
                    <div align="left">
                              <div class="row" style="margin-top:10px">
                              <div class="col-md-10 col-md-offset-1">

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Tanggal join</label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{date("d-M-Y",strtotime($agen->member_joindate))}}</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Referal agen (Kode)</label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label><?php if($agen->agen_sponsor_id=="")echo "-"; else echo $agen->agen_sponsor_id; ?></label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Kode agen</label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{$agen->agen_code}}</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Nama agen <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{$agen->member_name}}</label>                                  
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Alamat <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{$agen->member_address}}</label>
                                  </div>
                                  </div>
                                 
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Kota / Kabupaten <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label>{{$agen->regional_name}}</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Propinsi <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label>{{$agen->provinsi_name}}</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Nomor telepon / HP<font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label>{{$agen->member_phone}}</label>                
                                  </div>
                                  </div>

                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Alamat email<font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label>{{$agen->member_email}}</label>
                                  </div>
                                  </div>
                              </div> 
                              </div>   
                    
                    </div>
                    <div class="modal-footer">

                    <button class="btn btn-sm btn-dark" style=" margin-right:5px" class="close" data-dismiss="modal"><span class="fa fa-times"></span> Batal</button></a>
                         
                    </div>
                  </div>
                </div>
              </div>
@endforeach


</div>


@stop
@stop